<?php
include("include/config.inc.php");
$pageName = 'process';

if($_SESSION['s_userType'] == 'User')
{
   $authorization = "NoAccess";
   foreach($selUsermenuArr as $value)
   {
      if(in_array($pageName, $value))
      {
        $authorization ="Access";
        break;
      }
      else 
      {
        $authorization = "NoAccess";    
      }
   }
   if($authorization == "NoAccess")
   {
     header("location:index.php");
   }
}
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{	
  $i = 0;
  $processId   	= isset($_REQUEST['processId']) ? $_REQUEST['processId'] : 0;
  $processName 		= "";
  $isEdit 	= 0;
  $viewArr  = array();
    
  if(isset($_POST['insertBtn']))
  {
    if(isset($_POST['updateProcessId']) && $_POST['updateProcessId'] > 0)
    {
      $updateMarkoQuery = "UPDATE process
             								  SET processName = '".$_POST['processName']."'
	            								WHERE processId   = ".$_POST['updateProcessId'];
      $updateMarkoQueryResult = mysql_query($updateMarkoQuery);
      if(!$updateMarkoQueryResult)
      die("Update Query Not Inserted : ".mysql_error());
      else
      header("Location:process.php");  
    }       
    else
    {
      $insertQueryProcess = "INSERT INTO process (processName)
                              VALUE('".$_POST['processName']."')";
      $insertQueryProcessResult = mysql_query($insertQueryProcess);
      if(!$insertQueryProcessResult)
      die("Insert Query Not Inserted : ".mysql_error());
      else
      {
        header("Location:process.php");
      }
    }
  }
  $msg              = "Record Not Found";
  $editProcessId    = 0;
  $editProcessName  = "";
  $processDataArray = array();
  $i = 0;

  $selectProcess = "SELECT processId,processName
                   FROM process
                   ORDER BY processName";
  $selectProcessResult = mysql_query($selectProcess);
  while($ProcessdRow = mysql_fetch_array($selectProcessResult))
  {
	  $processDataArray[$i]['processId']     = $ProcessdRow['processId'];
	  $processDataArray[$i]['processName']   = $ProcessdRow['processName'];
	  if($ProcessdRow['processId']== $processId)
	{
	  $editProcessId   = $ProcessdRow['processId'];
		$editProcessName = $ProcessdRow['processName'];
	}
	  $i++;
  }
}
include("./bottom.php");
$smarty->assign("processDataArray",$processDataArray);
$smarty->assign("processId",$processId);
$smarty->assign("processName",$processName);
$smarty->assign("i",$i);
$smarty->assign("isEdit",$isEdit);
$smarty->assign("msg",$msg);
$smarty->assign("editProcessId",$editProcessId);
$smarty->assign("editProcessName",$editProcessName);
$smarty->display('process.tpl');

?>